const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    id:'',
    detail:'',
    logisticsdata:[],
    lognum:'',
    logisticsCompany:'',
  },
  onLoad(options) {
    if(options.id){
      this.setData({
        id:options.id
      })
      this.refunddetail()
    }
    this.logistics()
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  refunddetail(){
    Controller.refunddetail({orderNumber:this.data.id}).then(res=>{
      if(res.data.baseData){
        this.setData({
          detail:res.data.baseData,
        })
      }
    })
  },
  changedesc(e){
    this.setData({
      desc:e.detail.value
    })
  },
  changereson(e){
    this.setData({
      reson:e.detail.value
    })
  },
  logistics(){
    Controller.logistics({orderNumber:this.data.id}).then(res=>{
      if(res.data.baseData){
        this.setData({
          logisticsdata:res.data.baseData
        })
      }
    })
  },
  changelognum(e) {
      this.setData({
          lognum: e.detail.value
      })
  },
  changelogname(e) {
      this.setData({
          logisticsCompany: e.detail.value
      })
  },
  comfirm(){
    if(!this.data.logisticsCompany){
      wx.showToast({
        title: "请输入快递公司",
        icon: 'none',
        duration: 1000
      });
      return
    }
    if(!this.data.lognum){
      wx.showToast({
        title: "请输入快递单号",
        icon: 'none',
        duration: 1000
      });
      return
    }
    Controller.setRefundLogistics({orderNumber:this.data.id,logisticsNumber:this.data.lognum,logisticsCompany:this.data.logisticsCompany}).then(res=>{
        wx.showToast({
          title: "提交成功",
          icon: 'none',
          duration: 800
        });
        setTimeout(()=>{
          wx.redirectTo({
            url:'/pages/service/result?id='+this.data.id
          })
        },1000)
 
    })
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})